package com.example.imtoken.core.http

import com.blankj.utilcode.util.LogUtils
import com.blankj.utilcode.util.ToastUtils
import io.reactivex.Observer
import io.reactivex.disposables.Disposable

abstract class BaseObserver<T> : Observer<T> {

    protected abstract fun onSuccess(value: T)

    protected abstract fun onFailed(e: Throwable)

    override fun onSubscribe(d: Disposable) {

    }

    override fun onNext(value: T) {
        onSuccess(value)
    }

    override fun onError(e: Throwable) {
        ToastUtils.showShort(e.message)
        LogUtils.e(e.message)
        onFailed(e)
    }

    override fun onComplete() {

    }
}